package com.mk.model.vo.user;

import com.mk.model.entity.User;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Date;

@Data
public class UserVO implements Serializable {

    /**
     * id
     */
    private Long id;

    /**
     * 账号
     */
    private String userAccount;

    /**
     * 用户昵称
     */
    private String userNick;

    /**
     * 用户头像
     */
    private String userAvatar;

    /**
     * 用户简介
     */
    private String userProfile;

    /**
     * 用户角色：user/admin
     */
    private String userRole;

    /**
     * 创建时间
     */
    private Date createTime;

    private static final long serialVersionUID = 1L;

    /**
     * 对象转封装类
     * @param user
     * @return
     */
    public static UserVO objToVO(User user){
        if (user == null)
            return null;
        UserVO userVO = new UserVO();
        BeanUtils.copyProperties(user, userVO);
        return userVO;
    }

    /**
     * 封装类转对象
     * @param userVO
     * @return
     */
    public static User VOToObj(UserVO userVO){
        if (userVO == null)
            return null;
        User user = User.builder().build();
        BeanUtils.copyProperties(userVO, user);
        return user;
    }
}
